// 支付渠道常量定义

// 支付渠道枚举
export enum PaymentChannelId {
  WXPAY = 1,    // 微信支付
  ALIPAY = 2,    // 支付宝
  LESHUA = 3,    // 乐刷支付
  DOUGONG = 4    // 斗拱支付
}

// 支付渠道代码枚举
export enum PaymentChannelCode {
  WXPAY = 'WXPAY',
  ALIPAY = 'ALIPAY',
  LESHUA = 'LESHUA',
  DOUGONG = 'DOUGONG'
}

// 支付渠道信息接口
export interface ChannelInfo {
  id: number
  code: string
  name: string
  description?: string
  icon?: string
  color?: string
}

// 支付渠道映射表
export const PAYMENT_CHANNELS: Record<number, ChannelInfo> = {
  [PaymentChannelId.WXPAY]: {
    id: PaymentChannelId.WXPAY,
    code: PaymentChannelCode.WXPAY,
    name: '微信支付',
    description: '微信支付渠道',
    icon: 'wechat',
    color: '#07C160'
  },
  [PaymentChannelId.ALIPAY]: {
    id: PaymentChannelId.ALIPAY,
    code: PaymentChannelCode.ALIPAY,
    name: '支付宝',
    description: '支付宝支付渠道',
    icon: 'alipay',
    color: '#1677FF'
  },
  [PaymentChannelId.LESHUA]: {
    id: PaymentChannelId.LESHUA,
    code: PaymentChannelCode.LESHUA,
    name: '乐刷支付',
    description: '乐刷支付渠道',
    icon: 'leshua',
    color: '#FF6B35'
  },
  [PaymentChannelId.DOUGONG]: {
    id: PaymentChannelId.DOUGONG,
    code: PaymentChannelCode.DOUGONG,
    name: '斗拱支付',
    description: '斗拱支付渠道',
    icon: 'dougong',
    color: '#722ED1'
  }
}

// 工具函数：根据渠道ID获取渠道名称
export const getChannelNameById = (channelId: number): string => {
  return PAYMENT_CHANNELS[channelId]?.name || `未知渠道(${channelId})`
}

// 工具函数：根据渠道ID获取渠道信息
export const getChannelInfoById = (channelId: number): ChannelInfo | null => {
  return PAYMENT_CHANNELS[channelId] || null
}

// 工具函数：根据渠道代码获取渠道信息
export const getChannelInfoByCode = (channelCode: string): ChannelInfo | null => {
  return Object.values(PAYMENT_CHANNELS).find(channel => channel.code === channelCode) || null
}

// 工具函数：获取所有渠道列表
export const getAllChannels = (): ChannelInfo[] => {
  return Object.values(PAYMENT_CHANNELS)
}

// 工具函数：检查渠道ID是否有效
export const isValidChannelId = (channelId: number): boolean => {
  return channelId in PAYMENT_CHANNELS
}